"""
@Project:p8-master
@File:jwt_uilts.py
@Author:柴奇峰
@Date:20:54
"""
from flask import current_app,request,g
import jwt
def jwt_authentication():
    token = request.headers.get("Authorization")
    g.user_id = None

    # 判单token是否存在
    if token:
        key = current_app.config.get("SECRET_KEY")
        payload = jwt.decode(token, key=key, algorithms=['HS256'])
        # token 校验成功, 把用户id 写入g 对象
        g.user_id = payload.get('user_id')
        # 判断是否是刷新生成的token
        return None
